#!/bin/bash

RPATH=$1

echo "Changing root to ${RPATH:?}"

mkdir -pv $RPATH/{dev,proc,sys,run}
mknod -m 600 $RPATH/dev/console c 5 1
mknod -m 666 $RPATH/dev/null c 1 3
mount -v --bind /dev $RPATH/dev
mount -vt devpts devpts $RPATH/dev/pts -o gid=5,mode=620
mount -vt proc proc $RPATH/proc
mount -vt sysfs sysfs $RPATH/sys
mount -vt tmpfs tmpfs $RPATH/run

chroot "$RPATH" /usr/bin/env -i \
    HOME=/                  \
    TERM="$TERM"                \
    PS1='\[plx_chroot\] \u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin \
    /bin/bash --login



umount -v $RPATH/dev/pts
umount -v $RPATH/dev
umount -v $RPATH/run
umount -v $RPATH/proc
umount -v $RPATH/sys


